package org.example.filter;

import lombok.extern.slf4j.Slf4j;
import org.example.bean.Message;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @Auther:Liu
 * @Testname:Message
 * @Date:2025/9/15 17:25
 */
//⾃定义局部过滤器,类名必须是 yml ⽂件中的名字+GatewayFilterFactory
@Slf4j
@Component
public class MessageGatewayFilterFactory extends
        AbstractGatewayFilterFactory<Message> {
    public MessageGatewayFilterFactory() {
        super(Message.class);
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("first", "second", "third");
    }

    @Override
    public GatewayFilter apply(Message config) {
        log.info("config:{}", config);
        return (exchange, chain) -> {
            return chain.filter(exchange);
        };
    }
}
